{% extends "orga/submission/base.html" %}

{% load compress %}
{% load i18n %}
{% load rich_text %}
{% load rules %}
{% load static %}
{% load thumbnail %}

{% block submission_title %}{% translate "Speakers" %} :: {% endblock submission_title %}

{% block submission_content %}
    {% has_perm "base.update_submission" request.user submission as can_edit_speakers %}
    {% has_perm "base.send_queuedmail" request.user request.event as can_send_mails %}
    {% has_perm "base.mark_arrived_speakerprofile" request.user request.event as can_mark_speaker %}
    {% if can_edit_speakers %}<div class="alert">
        <form method="POST" class="form d-flex w-100 flex-column">
            {% csrf_token %}
            <div class="d-flex flex-row">
                <div class="w-50 hide-optional mr-4">{{ form.email.as_field_group }}</div>
                <div class="w-50">{{ form.name.as_field_group }}</div>
            </div>
            <div class="d-flex flex-row hide-optional">
                <div class="w-50 hide-optional mr-4">{% if form.locale %}{{ form.locale.as_field_group }}{% endif %}</div>
                <div class="w-50 mt-4"><button type="submit" class="btn btn-sm btn-success btn-block btn-lg mt-2"><i class="fa fa-plus"></i> {% translate "Add speaker" %}</button></div>
            </div>
        </form>
    </div>{% endif %}

    {% for speaker in speakers %}
        <div class="card mb-3"><div class="card-body">
            <h3 class="card-title">
                <a href="{% url "orga:speakers.view" event=request.event.slug code=speaker.user.code %}">
                    {{ speaker.user.get_display_name }}
                </a>
                {% if speaker.user.avatar and request.event.cfp.request_avatar %}
                    <div class="speaker-avatar">
                        <a href="{{ speaker.user.avatar.url }}" data-lightbox>
                            <img loading="lazy" width="100%" src="{{ speaker.user.avatar|thumbnail:"default" }}" alt="{% translate "The speaker’s profile picture" %}">
                        </a>
                    </div>
                {% endif %}
            </h3>
            {% if request.event.cfp.request_biography %}
                <p class="card-text">
                    <h5>{% translate "Biography" %}:</h5>
                    {{ speaker.profile.biography|rich_text|default:"-" }}
                </p>
            {% endif %}
            <p class="card-text">
                {% if speaker.other_submissions %}
                    <h5>{% translate "Other proposals by this speaker:" %}</h5>
                    <ul>
                        {% for submission in speaker.other_submissions %}
                            <li>
                                <a href="{{ submission.orga_urls.base }}">{{ submission.title }}</a>
                                {% include "cfp/event/fragment_state.html" with state=submission.state as_badge=True %}
                            </li>
                        {% endfor %}
                    </ul>
                {% endif %}
            </p>
            {% if can_edit_speakers %}
                {% if can_mark_speaker and submission.state in 'accepted,confirmed' %}
                    {% include "orga/includes/mark_speakers_arrived.html" with speaker=speaker.profile %}
                {% endif %}
                {% if can_send_mails %}
                    <a class="btn btn-outline-info" href="{{ request.event.orga_urls.compose_mails_sessions }}?speakers={{ speaker.user.code }}">
                        <i class="fa fa-envelope"></i>
                        {% translate "Send email" %}
                    </a>
                {% endif %}
                <a href="{% url "orga:speakers.view" event=request.event.slug code=speaker.user.code %}"
                   class="btn btn-info">
                    <i class="fa fa-edit"></i> {{ phrases.base.edit }}
                </a>
                <a href="{{ submission.orga_urls.delete_speaker }}?id={{ speaker.user.id }}"
                   class="btn btn-danger">
                    <i class="fa fa-trash"></i> {% translate "Remove" %}
                </a>
            {% endif %}
        </div></div>
    {% endfor %}

    <span id="vars" remoteUrl="{{ request.event.organiser.orga_urls.user_search }}"></span>
    {% compress js %}
        <script defer src="{% static "orga/js/speakers.js" %}"></script>
    {% endcompress %}
{% endblock submission_content %}
